#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int T,n,a[maxn];
void solve1(){
	int ans=-1;
	for(int i=0;i<(1<<n);i++){
		int res=0,prered=0,preblue=0;
		for(int j=1;j<=n;j++){
			if(i&(1<<(n-j))){if(a[prered]==a[j]) res+=a[j];prered=j;}
			else{if(a[preblue]==a[j]) res+=a[j];preblue=j;}
		}
		ans=max(res,ans);
	}
	cout<<ans<<endl;
}/*
int dp[maxn];
vector<int> to[1000005];
void solve2(){
    int ans=-1;
	for(int i=1;i<=n;i++){
		
	}
}
*/
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		if(1<=n&&n<=15) solve1();
//		else solve2();
	}
    return 0;
}
